#include "COMMON.h"


int main()
{
    EnableFile();
    // 创建 socket
    int sfd = socket(AF_UNIX, SOCK_STREAM, 0);
    if(sfd == -1)
        LOG(FATAL, "socket create failed");
    
    
    // 初始化地址格式
    struct sockaddr_un addr;
    memset(&addr, 0, sizeof(struct sockaddr_un));
    addr.sun_family = AF_UNIX;
    strncpy(addr.sun_path, SV_SOCK_PATH, sizeof(addr.sun_path) - 1);

    // 连接
    if(connect(sfd, (struct sockaddr*)&addr, sizeof(struct sockaddr_un)) == -1)
        LOG(ERROR, "connect");

    int cfd = -1;
    int numRead = 0;
    char buf[BUF_SIZE];
    
    while((numRead = read(STDIN_FILENO, buf, BUF_SIZE)) > 0)
        if(write(sfd, buf, numRead) != numRead)
            LOG(FATAL, "partial/failed write");
        
    if(numRead == -1)
        LOG(INFO, "read");
    exit(EXIT_SUCCESS);
    return 0;
}